<template>
  <div>
    <components title="确认订单"></components>
    <div class="content">
      <van-contact-card
      :type="cardType"
      :name="order.name"
      :tel="order.tel"
      @click="choseType"
    />
       <van-swipe-cell 
          v-for="item in items"
          :key='item.id'>
          <div class="item-card" v-if="item.isChecked">
              <van-card
                :num="item.num"
                :price="item.minPrice"
                :desc="item.characteristic"
                :title="item.name"
                :thumb="item.pic"
                class="goods-card">
              </van-card>
          </div>
          <!-- 步进器 -->
         <van-stepper v-if="item.isChecked" v-model="item.num"/>
        </van-swipe-cell>
        <van-button type="danger">付款</van-button>
    </div>
  </div>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
import components from '@/views/car/components/component'
export default {
    components: {
      components
    },
    created () {
      this.judge()
    },
    data () {
      return {
        cardType: 'edit',//add进入添加联系人页面，edit进入编辑联系人页面
        currentContact: {
          name: "小米",
          tel: '15636235689'
        }
      }
    },
    computed: {
      // 所有联系人数据
      ...mapState({
        orders: (state) => state.addcontact.contact,
        // 当前订单页联系人信息
        order: (state) => state.addcontact.preveContact
      }),
      // 购物车数据（给订单使用）
      ...mapState({
        items: (state) => state.cardata.items
      })
    },
    methods: {
      ...mapMutations('addcontact', ['choseContact']),
      judge () {
        // console.log(this.orders.length);
        if(this.order.name){
            console.log('edit')
            this.cardType = 'edit'
            return;
        }
        if(!this.orders.length){
          this.cardType = 'add'
          return;
        }
        let DefaultContact = this.orders.find(el => el.isDefault)
        if(DefaultContact){
          this.choseContact(DefaultContact)
        }else{
          // console.log(111);
          this.choseContact(this.orders[0])
        }
      },
      choseType () {
        if(this.cardType == 'add'){
          // 进入添加联系人页面
          this.$router.push('/addcontent')
        }else{
          // 进入编辑联系人页面
          this.$router.push('/contactlist')
        }
      }
    }
}
</script>

<style lang="scss" scoped>
  .content{
    margin-top: 46px;
    position: relative;
    .van-stepper{
      display: flex;
      justify-content: flex-end;
    }
    .van-button{
      width: 100%;
      position: absolute;
      margin-bottom: 50px;
    }
  }
</style>